// pages/nav/cms/nav_cms.js
const mybehavior = require("../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    active: 0,
    daiban_num: "",
    baseUrl: "https://logisticsengineering.gree.com/package_integrated_api",
    show1: true,
    show2: true,
    // 郑楚鑫从头部迁移过来
    self_info_show: false,
    self_info_show2: false,
    show: false,
    user_name: "",
    login_out_show: false,
    _id: "",
    company: "",
    name: "",
    ID_number: "",
    manager: "",
    phone_num: "",
    role: "",
    data_auth: "",
    self_info: {},
    yam_btn_disabled: false,
    yam_btn: "primary",
    yam_word: "发送",
    count: 0,
    new_ver_code: "",
    new_phonenum: "",
    new_name: "",
    new_ID_number: "",
    daiban_num: "",
    company_auth_count: "",
    container_auth_count: "",
    container_outdoor_count: "",
    people_auth_count: "",
    supply_register_count: "",
    third_register_count: "",
    select_style: "width: 136rpx;height: 48rpx;background: #5555FF;border-radius: 24rpx 24rpx 24rpx 24rpx;opacity: 1;position: absolute;top: 108rpx;left: 28rpx;",
    tag_style1: "position: absolute;top: 114rpx;left: 48rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;color:white;",
    tag_style2: "position: absolute;top: 114rpx;left: 196rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
    tag_style3: "position: absolute;top: 114rpx;left: 344rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
    tag_style4: "position: absolute;top: 114rpx;left: 492rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
    show11: true,
    show22: false,
    show33: false,
    show44: false,
    sqd_total:0


  },

  // 标签切换
  tagChange1() {

    this.setData({
      show11: true,
      show22: false,
      show33: false,
      show44: false,
      tag_style1: "position: absolute;top: 114rpx;left: 48rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;color:white;",
      tag_style2: "position: absolute;top: 114rpx;left: 196rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style3: "position: absolute;top: 114rpx;left: 344rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style4: "position: absolute;top: 114rpx;left: 492rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style3: "position: absolute;top: 114rpx;left: 344rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style4: "position: absolute;top: 114rpx;left: 492rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      select_style: "width: 136rpx;height: 48rpx;background: #5555FF;border-radius: 24rpx 24rpx 24rpx 24rpx;opacity: 1;position: absolute;top: 108rpx;left: 28rpx;",
    })
  },
  tagChange2() {
    this.setData({
      show11: false,
      show22: true,
      show33: false,
      show44: false,
      tag_style1: "position: absolute;top: 114rpx;left: 48rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;color: #666666;;",
      tag_style2: "position: absolute;top: 114rpx;left: 196rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;color:white;",
      tag_style3: "position: absolute;top: 114rpx;left: 344rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style4: "position: absolute;top: 114rpx;left: 492rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      select_style: "width: 136rpx;height: 48rpx;background: #5555FF;border-radius: 24rpx 24rpx 24rpx 24rpx;opacity: 1;position: absolute;top: 108rpx;left: 176rpx;",

    })
  },
  tagChange3() {
    this.setData({
      show11: false,
      show22: false,
      show33: true,
      show44: false,
      tag_style1: "position: absolute;top: 114rpx;left: 48rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style2: "position: absolute;top: 114rpx;left: 196rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style3: "position: absolute;top: 114rpx;left: 344rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;color:white;",
      tag_style4: "position: absolute;top: 114rpx;left: 492rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      select_style: "width: 136rpx;height: 48rpx;background: #5555FF;border-radius: 24rpx 24rpx 24rpx 24rpx;opacity: 1;position: absolute;top: 108rpx;left: 324rpx;",
    })
  },
  tagChange4() {
    this.setData({
      show11: false,
      show22: false,
      show33: false,
      show44: true,
      tag_style1: "position: absolute;top: 114rpx;left: 48rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style2: "position: absolute;top: 114rpx;left: 196rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style3: "position: absolute;top: 114rpx;left: 344rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;",
      tag_style4: "position: absolute;top: 114rpx;left: 492rpx;width: 96rpx;height: 36rpx;font-size: 24rpx;font-weight: 600;color: #666666;line-height: 36rpx;color:white;",
      select_style: "width: 136rpx;height: 48rpx;background: #5555FF;border-radius: 24rpx 24rpx 24rpx 24rpx;opacity: 1;position: absolute;top: 108rpx;left: 472rpx;",
    })
  },
  routeJump(e) {
    this.checkAuth(e)

  },
  // 获取待办数量
  // getBaseDate() {
  //   var url = this.data.baseUrl + "/badge_manage/query_badge_count";
  //   var data = {}
  //   this.post(url, data).then(res => {
  //     this.setData({
  //       daiban_num: res.data.total_count
  //     })

  //   }).catch(err => {
  //     wx.showToast({
  //       title: err.msg,
  //       icon: 'error'
  //     })
  //   })
  // },
  // 切换页面
  
  
  changePage(ev) {

    wx.navigateTo({
      url: ev.currentTarget.dataset.url,
    })
  },

  onChange(event) {
    wx.showToast({
      title: `切换到标签 ${event.detail.name}`,
      icon: 'none',
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  sentBtn() {
    var a = this.data.count
    var t = this.data.yam_word
    if (a < 60) {
      this.setData({
        yam_word: t - 1,
        count: a + 1,
      })
      setTimeout(() => {
        this.sentBtn()
      }, 1000)
    } else {
      this.setData({
        yam_btn_disabled: false,
        yam_word: "发送"
      })

    }

  },
  // 发送验证码
  sentCode() {
    let self = this
    if (self.data.new_phonenum == "") {
      wx.showToast({
        title: "不能为空",
        icon: "error"
      })
    } else {
      var url = self.data.baseUrl + "/login_manage/get_verification_code2";
      var data = {
        phone_num: self.data.new_phonenum,
      }
      var token = wx.getStorageSync('token')
      console.log("发送验证码", data)
      wx.request({
        url,
        data,
        header: {
          "Authorization": token
        },
        dataType: "json",
        method: "POST",
        success(res) {
          const result = res.data
          if (result.code == 20000) {
            self.setData({
              yam_btn_disabled: true,
              yam_word: 60,
              count: 0,
            })
            self.sentBtn()
            wx.showToast({
              title: result.msg,
              icon: "success"
            });
          } else {
            // self.setData({
            //   phone_num: "",
            // })
            wx.showToast({
              title: result.msg,
              icon: "error"
            })
          }

        },
        fail(res) {
          console.log(res);

        }
      });
    }


  },

  // 修改账户信息
  updateSelfInfo() {
    let self = this
    var url = this.data.baseUrl + "/user_manage/outer_update_self_r";
    var data = {
      key: this.data.phone_num,
      new_ID_number: this.data.new_ID_number,
      new_name: this.data.new_name,
      new_phonenum: this.data.new_phonenum,
      new_ver_code: this.data.new_ver_code,
      old_ID_number: this.data.ID_number,
      old_name: this.data.name,
      old_phonenum: this.data.phone_num,
    }
    var token = wx.getStorageSync('token')
    wx.request({
      url,
      data,
      header: {
        "Authorization": token
      },
      dataType: "json",
      method: "POST",
      success(res) {
        const result = res.data
        self.setData({
          self_info_show2: false,
          new_ver_code: ""
        })
        wx.showToast({
          title: result.msg,
          icon: "success"
        });
        console.log(result.data);
      },
      fail(res) {
        console.log(res);
      }
    });
  },
  showSelfInfo() {
    this.setData({
      self_info_show: true
    })
  },
  showSelfInfo2() {
    this.setData({
      self_info_show2: true
    })
  },

  loginOut() {
    this.setData({
      login_out_show: true
    })
  },
  onConfirm() {
    this.setData({
      self_info: "",
      _id: "",
      company: "",
      manager: "",
      phone_num: "",
      ID_number: "",
      name: "",
      user_name: "",
      role: "",
      new_phonenum: "",
      new_name: "",
      new_ID_number: "",
      data_auth: "",
    })
    wx.clearStorage()
    wx.reLaunch({
      url: '/pages/login1/login',
    });
  },
  onClose() {
    this.setData({
      login_out_show: false
    })
  },
  onConfirm1() {
    this.setData({
      self_info_show: false
    })
  },
  onClose1() {
    this.setData({
      self_info_show: false
    })
  },
  onConfirm2() {
    this.setData({
      self_info_show2: false
    })
  },
  onClose2() {
    this.setData({
      self_info_show2: false
    })
  }
})